package com.jeff.tianti.controller.channel;

import com.jeff.tianti.cms.dto.font.CnaaTo;
import com.jeff.tianti.cms.entity.CnaaApplyFor;
import com.jeff.tianti.cms.entity.CnaaFlow;
import com.jeff.tianti.cms.service.CnaaApplyForService;
import com.jeff.tianti.cms.service.CnaaFlowService;
import com.jeff.tianti.common.PageBean;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.BaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/channel/cnaa")//江苏频道_证明商标
@CrossOrigin(maxAge = 3600)
public class CnaaConrtoller {
    @Autowired
    private CnaaApplyForService cnaaApplyForService;
    @Autowired
    private CnaaFlowService cnaaFlowService;

    /**
     * @Ceator:liuYI
     * @Describe:证明商标_在线申请
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public AjaxResult saveCnaa(@RequestBody CnaaApplyFor cnaaApplyFor) {
        cnaaApplyFor.setAuditFlag(BaseEntity.AUDIT_FLAG_NOT);
        cnaaApplyForService.save(cnaaApplyFor);
        return AjaxResult.setSuccessData(null);
    }

    /**
     * @Ceator:liuYI
     * @Describe:cnaa在线申请流程列表
     */
    @RequestMapping(value = "/flowList", method = RequestMethod.GET)
    public AjaxResult findCnaaFlow() {
        List<CnaaFlow> cnaaFlows = cnaaFlowService.queryCnaaFlowList(null);
        return AjaxResult.setSuccessData(cnaaFlows);
    }

    /**
     * @Ceator:liuYI
     * @Describe:江苏频道_获批企业列表
     */
    @RequestMapping(value = "/applyList", method = RequestMethod.POST)
    public AjaxResult findCnaaApplyFor(@RequestBody CnaaTo cnaaTo) {
        Pageable pageable = new PageRequest(cnaaTo.getCurrentPage(), cnaaTo.getPageSize(), Sort.Direction.DESC, "updateDate");
        Page<CnaaApplyFor> page = cnaaApplyForService.findAllNoDel(cnaaTo.getLevel(), pageable);
        return AjaxResult.setSuccessPageDate(page);
    }

    /**
     * @Ceator:liuYI
     * @Describe:江苏频道_获批企业_详情查看
     */
    @RequestMapping(value = "/details", method = RequestMethod.GET)
    public AjaxResult findCnaaApplyForById(@RequestParam("id") String id) {
        CnaaApplyFor cnaaApplyFor = cnaaApplyForService.find(id);
        return AjaxResult.setSuccessData(cnaaApplyFor);
    }
}
